package com.base.message.action;

import com.base.common.action.AbstractBaseAction;
import com.base.common.bean.ActionResult;
import com.base.message.service.MessageService;
import com.cjy.common.bean.OpAttributes;
import com.cjy.user.service.UserService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import javax.annotation.Resource;

import static com.base.GlobaConstants.*;

/**
 * 消息通知等action控制管理中心
 * 
 * @author kat.luhongkai
 *
 */
@Action("messageAction")
@Results({ @Result(name = ASYNCHRONOUS, type = JSON, params = { ROOT,
		ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_JSON }) })
public class MessageAction extends AbstractBaseAction{
	
	private static final long serialVersionUID = 1L;
	
	private int compoundsId;	// 小区id
	
	@Resource
	private MessageService messageService;
	
	private int page;			// 当前页数
	private int type;			// 消息类型
	@Resource
	private UserService userService;
	
	
	

	public int getCompoundsId() {
		return compoundsId;
	}

	/**
	 * 获取消息列表
	 * 
	 * @return
	 */
	public String getMessage() {
		try {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 1).add("result", messageService.getMessages(page, type, compoundsId)));
		}catch(Exception e) {
			actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 0));
		}
		return returnType();
	}

	public int getPage() {
		return page;
	}

	public int getType() {
		return type;
	}

	public void setCompoundsId(int compoundsId) {
		this.compoundsId = compoundsId;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
	public void setType(int type) {
		this.type = type;
	}
	
	public String test() {
//		messageService.testMysqlConnection();
		actionResult = ActionResult.getActionResult(new OpAttributes().add("code", 0));
		return returnType();
	}

}
